package com.spring.beans.factory.support;

import com.spring.beans.BeansException;
import com.spring.beans.factory.config.BeanDefinition;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

/**
 * @Description: This is a sample class.
 * @Author: Simon
 */
public class CglibSubclassingInstantiationStrategy implements InstantiationStrategy {

    // 根据CGLIB动态生成子类
    @Override
    public Object instantiate(BeanDefinition beanDefinition) throws BeansException {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(beanDefinition.getBeanClass());
        enhancer.setCallback((MethodInterceptor) (obj, method, argsTemp, proxy) -> proxy.invokeSuper(obj, argsTemp));
        return null;
    }
}
